package com.hschinese.pronunciation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.utils.Logger;
import com.hschinese.pronunciation.widget.ConsonantsGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wo on 2015/11/9.
 */
public class ConsonantListViewAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private Context mContext = null;
    private List<String> mData;

    public ConsonantListViewAdapter(Context context, List<String> data) {
        inflater = LayoutInflater.from(context);
        mContext = context;
        mData = data;
    }

    @Override
    public int getCount() {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        Logger.e("xionghy-listview adapter getView -----------------------------");
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.consonants_listview_item, parent, false);
            holder = new ViewHolder();
            holder.mTitleText = (TextView)convertView.findViewById(R.id.consonants_listview_item_text);
            holder.gridView = (ConsonantsGridView)convertView.findViewById(R.id.consonants_listview_item_gridview);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        // TODO 添加响应和数据更新
        holder.mTitleText.setText(mData.get(position));
        holder.gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Logger.e("xionghy-onItemClick: " + position + "-----------------");
            }
        });
        ConsonantsGridViewAdapter mAdapter = new ConsonantsGridViewAdapter(mContext, getData(position));
        holder.gridView.setAdapter(mAdapter);
        return convertView;
    }

    class ViewHolder {
        public TextView mTitleText;
        public ConsonantsGridView gridView;
    }

    private List<String> getData(int i) {
        List<String> list = new ArrayList<String>();
        for (int j=0; j<i+1; j++) {
            list.add(i + "-" + j);
        }
        return list;
    }
}
